#include <QDebug>
#include "CurrentEditor.h"

CurrentEditor::CurrentEditor(QObject* parent):QObject(parent)
{

}

CurrentEditor::~CurrentEditor()
{

}

void CurrentEditor::setEditor(PluginWrapper<Plugins::IEditor> & ed)
{
    if (!_ed.isNull()){
        disconnect(_ed, SIGNAL(undoAvailable(bool)));
        disconnect(_ed, SIGNAL(redoAvailable(bool)));
        disconnect(_ed, SIGNAL(copyAvailable(bool)));
        disconnect(_ed, SIGNAL(modifyChanged(bool)));
        disconnect(_ed, SIGNAL(errorListChanged(QAbstractTableModel*)));
    }
    _ed = ed;
    connect(_ed, SIGNAL(undoAvailable(bool)), SIGNAL(undoAvailable(bool)));
    connect(_ed, SIGNAL(redoAvailable(bool)), SIGNAL(redoAvailable(bool)));
    connect(_ed, SIGNAL(copyAvailable(bool)), SIGNAL(copyAvailable(bool)));
    connect(_ed, SIGNAL(modifyChanged(bool)), SIGNAL(modifyChanged(bool)));
    connect(_ed, SIGNAL(errorListChanged(QAbstractTableModel*)), SIGNAL(errorListChanged(QAbstractTableModel*)));
    connect(_ed, SIGNAL(fileNavigate(QString, int)), SIGNAL(fileNavigate(QString, int)));
    //void pasteAviable(bool);

    _ed->activate();
}

PluginWrapper<Plugins::IEditor> CurrentEditor::editor()
{
    return _ed;
}

void CurrentEditor::testSlot(bool res)
{
    qDebug() << "!!!!" << res;
}

void CurrentEditor::undo(){if (!_ed.isNull()) _ed->undo();}
void CurrentEditor::redo(){if (!_ed.isNull()) _ed->redo();}
void CurrentEditor::copy(){if (!_ed.isNull()) _ed->copy();}
void CurrentEditor::cut(){if (!_ed.isNull()) _ed->cut();}
void CurrentEditor::paste(){if (!_ed.isNull()) _ed->paste();}
void CurrentEditor::del(){if (!_ed.isNull()) _ed->del();}
void CurrentEditor::selectAll(){if (!_ed.isNull()) _ed->selectAll();}

void CurrentEditor::setFocus()
{
    if (!_ed.isNull())
        _ed->widget()->setFocus();
}

QString CurrentEditor::selectedText()
{
    return _ed->selectedText();
}

void CurrentEditor::find(const QString& find, bool forward)
{
    if (!_ed.isNull())
        _ed->find(find, forward);
}

void CurrentEditor::replace(const QString& find, const QString& replace, bool findNext, bool forward)
{
    if (!_ed.isNull())
        _ed->replace(find, replace, findNext, forward);
}

void CurrentEditor::replaceAll(const QString& find, const QString& replace)
{
    if (!_ed.isNull())
        _ed->replaceAll(find, replace);
}

void CurrentEditor::uppercase()
{
    if (!_ed.isNull())
        _ed->uppercase();
}

void CurrentEditor::lowercase()
{
    if (!_ed.isNull())
        _ed->lowercase();
}

void CurrentEditor::capitalize()
{
    if (!_ed.isNull())
        _ed->capitalize();
}

void CurrentEditor::save()
{
    if (!_ed.isNull())
        _ed->save();
}

bool CurrentEditor::reset()
{
    return _ed->reset();
}

void CurrentEditor::jumpLine(int lineNo)
{
    _ed->jumpLine(lineNo);
}

void CurrentEditor::jumpOffset(int offset)
{
    _ed->jumpOffset(offset);
}
